# -*- coding: utf-8 -*-
#   针对一张表的编辑维护的定义，上部是Edit,下部是Grid定义, 继承基类
#   t_oneConfig, t_oneConfigEdit, t_oneConfigBrowse
#   eb: edit, browse各取第一各字母

# @Time    ： 2024/4/7  22:37
# @Auther  ： 徐良
# File     :  ebWork.py
from PySide6.QtCore import QItemSelection, QItemSelectionModel, Signal, QTimer
from PySide6.QtWidgets import QLabel, QDataWidgetMapper
from mesParts.model.tableModelMap import TableModelMap
from mesParts.model.tableModel import TableModel
from share.bioDialog import Infomation
from share.dataFactory import SqlForSave
from share.modelFunction import getModel
from share.sqlFunction import addWhereCondition_Str, getUpdateSqlListByModelFIdList, getInsertSqlList
from utils.baseWork import BaseWork
from mesParts.lineEdit.lineEdits import HeadLineEditStr, HeadLineEditInt, HeadLineEditFloat
from mesParts.lineEdit.f7LineEdits import F7HeadLineEdit
from mesParts.components.lineEdits import LineEditPath
from mesParts.label.labels import Label1, Label2, Label3
from mesParts.checkBox.checkBoxs import CustCheckBox
from PySide6.QtWidgets import QLineEdit
from PySide6.QtGui import QPixmap


class EBWork(BaseWork):
    """
    单表工作类
    """
    auditAfter = Signal(dict)  # row: 记录号， iFlag: 1 审核，0 未审核

    def __init__(self, msDict=None, parent=None):
        super(EBWork, self).__init__(parent)
        self.PixmapAudit = QPixmap('./resource/stamp/审核图章.png')
        self.toolbarStateTimer = QTimer()

    def doInitWork(self, msDict):
        """
        设置工作类初始化
        :return:
        """
        self.initWork(msDict)
        # 初始化本类
        self.__initBaseConfig()

    def __initBaseConfig(self):
        """
        # 基础表配置表表头初始化
        :return:
        """
        sql = "select * from t_formGridConfig where FNumber='{sfnumber}'".format(sfnumber=self.msFNumber)
        self.sysAppFormGfigModel = getModel(sql, self.baseDbType)

        pfid = self.sysAppFormGfigModel.record(0).value('FId')
        sql = "select * from t_fgEdit where FEntityId={sid} order by FXh".format(sid=str(pfid))
        self.sysAppEditModel = getModel(sql, self.baseDbType)

        sql = "select * from t_fgBrowse where FEntityId={sid} order by FXh".format(sid=str(pfid))
        self.sysAppBrowseModel = getModel(sql, self.baseDbType)

        self.__setSystemAppFormGridArr()

    def __setSystemAppFormGridArr(self):
        """

        :return:
        """

        self.__A2_FFieldList = []
        self.__A2_FFieldNameList = []
        self.__A2_FFieldTypeList = []
        self.__A2_FAlignList = []
        self.__A2_FTableWidthList = []
        self.__A2_FTreeWidthList = []
        self.__A2_FIsEditList = []
        self.__A2_FVisibleList = []
        self.__A2_FJoinSqlList = []
        self.__A2_FIsF7List = []

        self.__A2_FLabelNameList = []
        self.__A2_FWidgetList = []
        self.__A2_FRowList = []
        self.__A2_FColumnList = []
        self.__A2_FRowSpanList = []
        self.__A2_FColumnSpanList = []

        self.__A2_FPlaceHolderText = []
        self.__A2_FDefaultValue = []
        self.__A2_FMustInput = []
        self.__A2_FDecimal = []
        self.__A2_FRang = []

        for row in range(0, self.sysAppEditModel.rowCount()):
            self.__A2_FFieldList.append(self.sysAppEditModel.record(row).value('FField'))
            self.__A2_FFieldNameList.append(self.sysAppEditModel.record(row).value('FFieldName'))
            self.__A2_FFieldTypeList.append(self.sysAppEditModel.record(row).value('FFieldType'))
            self.__A2_FAlignList.append(self.sysAppEditModel.record(row).value('FAlign'))
            self.__A2_FTableWidthList.append(self.sysAppEditModel.record(row).value('FTableWidth'))
            self.__A2_FTreeWidthList.append(self.sysAppEditModel.record(row).value('FTreeWidth'))
            self.__A2_FIsEditList.append(self.sysAppEditModel.record(row).value('FIsEdit'))
            self.__A2_FVisibleList.append(self.sysAppEditModel.record(row).value('FVisible'))
            self.__A2_FJoinSqlList.append(self.sysAppEditModel.record(row).value('FJoinSql'))
            self.__A2_FIsF7List.append(self.sysAppEditModel.record(row).value('FIsF7'))
            self.__A2_FLabelNameList.append(self.sysAppEditModel.record(row).value('FLabelName'))
            self.__A2_FWidgetList.append(self.sysAppEditModel.record(row).value('FWidget'))
            self.__A2_FRowList.append(self.sysAppEditModel.record(row).value('FRow'))
            self.__A2_FColumnList.append(self.sysAppEditModel.record(row).value('FColumn'))
            self.__A2_FRowSpanList.append(self.sysAppEditModel.record(row).value('FRowSpan'))
            self.__A2_FColumnSpanList.append(self.sysAppEditModel.record(row).value('FColumnSpan'))

            self.__A2_FPlaceHolderText.append(self.sysAppEditModel.record(row).value('FPlaceHolderText'))
            self.__A2_FDefaultValue.append(self.sysAppEditModel.record(row).value('FDefaultValue'))
            self.__A2_FMustInput.append(self.sysAppEditModel.record(row).value('FMustInput'))
            self.__A2_FDecimal.append(self.sysAppEditModel.record(row).value('FDecimal'))
            self.__A2_FRang.append(self.sysAppEditModel.record(row).value('FRang'))

        self.__A3_FFieldList = []
        self.__A3_FFieldNameList = []
        self.__A3_FFieldTypeList = []
        self.__A3_FAlignList = []
        self.__A3_FColumnWidthList = []
        self.__A3_FIsEditList = []
        self.__A3_FVisibleList = []
        self.__A3_FJoinSqlList = []
        self.__A3_FWidgetList = []

        for row in range(0, self.sysAppBrowseModel.rowCount()):
            self.__A3_FFieldList.append(self.sysAppBrowseModel.record(row).value('FField'))
            self.__A3_FFieldNameList.append(self.sysAppBrowseModel.record(row).value('FFieldName'))
            self.__A3_FFieldTypeList.append(self.sysAppBrowseModel.record(row).value('FFieldType'))
            self.__A3_FAlignList.append(self.sysAppBrowseModel.record(row).value('FAlign'))
            self.__A3_FColumnWidthList.append(self.sysAppBrowseModel.record(row).value('FColumnWidth'))
            self.__A3_FIsEditList.append(self.sysAppBrowseModel.record(row).value('FIsEdit'))
            self.__A3_FVisibleList.append(self.sysAppBrowseModel.record(row).value('FVisible'))
            self.__A3_FJoinSqlList.append(self.sysAppBrowseModel.record(row).value('FJoinSql'))
            self.__A3_FWidgetList.append(self.sysAppBrowseModel.record(row).value('FWidget'))

    # -----------------------------------------
    def getA1_FTableName(self):
        """
        获取t_formGridConfig 符合条件的记录中的FTableName内容
        :return:
        """
        return self.sysAppFormGfigModel.record(0).value('FTableName')

    def getA1_FEditTitle(self):
        """
        获取t_formGridConfig 符合条件的记录中的FLabelTitle内容
        :return:
        """
        return self.sysAppFormGfigModel.record(0).value('FEditTitle')

    def getA1_FBrowseTitle(self):
        """
        获取t_formGridConfig 符合条件的记录中的FLabelTitle内容
        :return:
        """
        return self.sysAppFormGfigModel.record(0).value('FBrowseTitle')

    def getA1_FMainSql(self):
        """
        获取t_formGridConfig 符合条件的记录中的FTreeSql内容
        :return:
        """
        return self.sysAppFormGfigModel.record(0).value('FMainSql')

    def getA1_FTreeSql(self):
        """
        获取t_formGridConfig 符合条件的记录中的FTreeSql内容
        :return:
        """
        return self.sysAppFormGfigModel.record(0).value('FTreeSql')

    def getA1_FStateFieldName(self):
        """
        获取t_formGridConfig 符合条件的记录中的FStateFieldName内容
        :return:
        """
        return self.sysAppFormGfigModel.record(0).value('FStateFieldName')

    def getA1_FEnumClass(self):
        """
        获取t_formGridConfig 符合条件的记录中的FEnumClass内容
        :return:
        """
        return self.sysAppFormGfigModel.record(0).value('FEnumClass')

    def getA1_FColorGroup(self):
        """
        获取t_formGridConfig 符合条件的记录中的FColorGroup内容
        :return:
        """
        return self.sysAppFormGfigModel.record(0).value('FColorGroup')

    def getA1_FChoiceField(self):
        """
        获取t_formGridConfig 符合条件的记录中的FChoiceField内容
        :return:
        """
        return self.sysAppFormGfigModel.record(0).value('FChoiceField')

    def getA1_FChoiceValue(self):
        """
        获取t_formGridConfig 符合条件的记录中的FChoiceValue内容
        :return:
        """
        return self.sysAppFormGfigModel.record(0).value('FChoiceValue')

    # -------------------------------------------- edit 子表的列表    -----------------------
    def getA2_FFieldList(self):
        """
        获取系统表子表字段列表
        :return:
        """
        return self.__A2_FFieldList

    def getA2_FFieldNameList(self):
        """
        获取系统表子表字段名列表
        :return:
        """
        return self.__A2_FFieldNameList

    def getA2_FIsEditList(self):
        """
        获取系统表子表字段是否允许编辑列表
        :return:
        """
        return self.__A2_FIsEditList

    def getA2_FVisibleList(self):
        """
        获取系统表子表字段是否可见列表
        :return:
        """
        return self.__A2_FVisibleList

    def getA2_FJoinSqlList(self):
        """
        获取系统表子表字段是否参加sql语句列表
        :return:
        """
        return self.__A2_FJoinSqlList

    def getA2_FIsF7List(self):
        """
        获取系统表子表字段是否参加sql语句列表
        :return:
        """
        return self.__A2_FIsF7List

    def getA2_FWidgetList(self):
        """
        获取系统表子表字段所用控件列表
        :return:
        """
        return self.__A2_FWidgetList

    def getA2_FLabelNameList(self):
        """
        获取系统表子表字段标签名列表
        :return:
        """
        return self.__A2_FLabelNameList

    def getA2_FAlignList(self):
        """
        获取系统表子表字段对齐方式列表
        :return:
        """
        return self.__A2_FAlignList

    def getA2_FRowList(self):
        """
        获取系统表子表字段所在行列表
        :return:
        """
        return self.__A2_FRowList

    def getA2_FColumnList(self):
        """
        获取系统表子表字段所在列列表
        :return:
        """
        return self.__A2_FColumnList

    def getA2_FRowSpanList(self):
        """
        获取系统表子表字段跨行列表
        :return:
        """
        return self.__A2_FRowSpanList

    def getA2_FColumnSpanList(self):
        """
        获取系统表子表字段跨列列表
        :return:
        """
        return self.__A2_FColumnSpanList

    def getA2_FPlaceHolderTextList(self):
        """
        获取系统表子表字段提示语列表
        :return:
        """
        return self.__A2_FPlaceHolderText

    def getA2_FDefaultValueList(self):
        """
        获取系统表子表字段缺省值列表
        :return:
        """
        return self.__A2_FDefaultValue

    def getA2_FMustInputList(self):
        """
        获取系统表子表字段是否必录列表
        :return:
        """
        return self.__A2_FMustInput

    def getA2_FDecimalList(self):
        """
        获取系统表子表字段小数位数列表
        :return:
        """
        return self.__A2_FDecimal

    def getA2_FRangList(self):
        """
        获取系统表子表字段数值范围列表
        :return:
        """
        return self.__A2_FRang

    # -------------------------------------------- browse 子表的列表    -----------------------
    def getA3_FFieldList(self):
        """
        获取系统表子表字段列表
        :return:
        """
        return self.__A3_FFieldList

    def getA3_FFieldNameList(self):
        """
        获取系统表子表字段名列表
        :return:
        """
        return self.__A3_FFieldNameList

    def getA3_FFieldTypeList(self):
        """
        获取系统表子表字段类型列表
        :return:
        """
        return self.__A3_FFieldTypeList

    def getA3_FColumnWidthList(self):
        """
        获取系统表子表字段列宽
        :return:
        """
        return self.__A3_FColumnWidthList

    def getA3_FAlignList(self):
        """
        获取系统表子表字段-对齐列表
        :return:
        """
        return self.__A3_FAlignList

    def getA3_FWidgetList(self):
        """
        获取系统表子表字段-控件列表
        :return:
        """
        return self.__A3_FWidgetList

    def getA3_FIsEditList(self):
        """
        获取系统表子表字段-是否可编辑列表
        :return:
        """
        return self.__A3_FIsEditList

    def getA3_FVisibleList(self):
        """
        获取系统表子表字段-是否可见列表
        :return:
        """
        return self.__A3_FVisibleList

    def getA3_FJoinSqlList(self):
        """
        获取系统表子表字段-是否参加SQL列表
        :return:
        """
        return self.__A3_FJoinSqlList

    #   *********************************** 面板设置    ***************************
    def initPara(self):
        """
            参数初始化
            :return:
        """
        # 取数据表名
        self.FTableName = self.getA1_FTableName()
        self.FMainSql = self.getA1_FMainSql()
        self.FTreeSql = self.getA1_FTreeSql()
        self.FEditTitle = self.getA1_FEditTitle()
        self.FBrowseTitle = self.getA1_FBrowseTitle()

        self.browse_FFieldList = self.getA3_FFieldList()
        self.browse_FFieldTypeList = self.getA3_FFieldTypeList()
        self.browse_FJoinSqlList = self.getA3_FJoinSqlList()
        self.browse_FFieldNameList = self.getA3_FFieldNameList()

        self.browse_FAlignList = self.getA3_FAlignList()
        self.browse_FColumnWidthList = self.getA3_FColumnWidthList()
        self.browse_FVisibleList = self.getA3_FVisibleList()
        self.browse_FWidgetList = self.getA3_FWidgetList()
        self.browse_FIsEditList = self.getA3_FIsEditList()

        self.edit_FFieldList = self.getA2_FFieldList()
        self.edit_FWidgetList = self.getA2_FWidgetList()
        self.edit_FLabelNameList = self.getA2_FLabelNameList()
        self.edit_FFVisibleList = self.getA2_FVisibleList()
        self.edit_FIsEditList = self.getA2_FIsEditList()
        self.edit_FIsF7List = self.getA2_FIsF7List()
        self.edit_FAlignList = self.getA2_FAlignList()

        self.edit_FRowList = self.getA2_FRowList()
        self.edit_FColumnList = self.getA2_FColumnList()
        self.edit_FRowSpanList = self.getA2_FRowSpanList()
        self.edit_FColumnSpanList = self.getA2_FColumnSpanList()

        self.edit_FPlaceHolderTextList = self.getA2_FPlaceHolderTextList()
        self.edit_FDefaultValueList = self.getA2_FDefaultValueList()
        self.edit_FMustInputList = self.getA2_FMustInputList()
        self.edit_FDecimalList = self.getA2_FDecimalList()
        self.edit_FRangList = self.getA2_FRangList()

    def _getWidgetDict(self, iRow):
        """
        获取控件需要的字典参数
        :param iRow:
        :return:
        """
        pDict = {'PlaceHolder': self.edit_FPlaceHolderTextList[iRow],
                 'DefaultValue': self.edit_FDefaultValueList[iRow],
                 'MustInput': self.edit_FMustInputList[iRow],
                 'Decimal': self.edit_FDecimalList[iRow],
                 'Rang': self.edit_FRangList[iRow]}

        return pDict

    def __setColumnAndSpacer(self, editGrid):
        """
        设置编辑面板行数和行高
        :param gridTop:
        :return:
        """
        # 取页头页脚设置参数
        for i in range(0, 8):
            editGrid.setColumnStretch(i, 1)  # 按照布局中其他列的比例来分配剩余空间，即它会占据相等的宽度

        # 设置水平间距为 20 像素
        editGrid.setHorizontalSpacing(25)

    def createGrid(self, grid):
        """
        创建网格
        :return:
        """
        self.__setColumnAndSpacer(grid)
        self.__lblList = []
        self.__hObj = []

        def setPosition(sLbl, sRow, sColumn, sRowSpan, sColumnSpan, sObj):
            if sLbl is not None:
                sLbl.setMinimumWidth(80)
                sLbl.setMaximumWidth(200)

            sObj.setMinimumWidth(100)
            sObj.setMaximumWidth(2000)

            if sLbl is not None:
                grid.addWidget(sLbl, sRow, sColumn, sRowSpan, sColumnSpan)

            grid.addWidget(sObj, sRow, sColumn + 1, sRowSpan, sColumnSpan)
            grid.setColumnStretch(sColumn, 1)
            grid.setColumnStretch(sColumn + 1, 2)

        ixh = 0
        for visible, field, widget, label, row, column, rowSpan, \
            columnSpan, isf7 in zip(self.edit_FFVisibleList,
                                    self.edit_FFieldList,
                                    self.edit_FWidgetList,
                                    self.edit_FLabelNameList,
                                    self.edit_FRowList,
                                    self.edit_FColumnList,
                                    self.edit_FRowSpanList,
                                    self.edit_FColumnSpanList,
                                    self.edit_FIsF7List):

            obj = None
            if visible == 1:
                if widget == 'HeadLineEditStr':
                    lbl = Label3(label)
                    self.__lblList.append(lbl)  # 当有红字时使用，或设置样式
                    pdict = self._getWidgetDict(ixh)

                    obj = HeadLineEditStr(pdict, self)

                    obj.setObjectName(field)
                    # setFieldIsEdit(obj, field, isEdit)
                    # obj.editingFinished.connect(self.onUpdate_model_data)
                    # 设置网格
                    setPosition(lbl, row, column, rowSpan, columnSpan, obj)
                    # 设置align
                    # setEditLineAlign(obj, align)

                elif widget == 'HeadLineEditInt':
                    lbl = Label3(label)
                    self.__lblList.append(lbl)  # 当有红字时使用，或设置样式

                    obj = HeadLineEditInt(self)

                    obj.setObjectName(field)
                    # setFieldIsEdit(obj, field, isEdit)
                    # obj.editingFinished.connect(self.onUpdate_model_data)
                    # 设置网格
                    setPosition(lbl, row, column, rowSpan, columnSpan, obj)
                    # 设置align
                    # setEditLineAlign(obj, align)

                elif widget == 'LineEditPath':
                    lbl = Label3(label)
                    self.__lblList.append(lbl)  # 当有红字时使用，或设置样式
                    pdict = {'model': self.mainModel, 'iCol': ixh,
                             'tableView': self.tableView}
                    obj = LineEditPath(pdict, self)

                    obj.setObjectName(field)
                    # setFieldIsEdit(obj, field, isEdit)
                    # obj.editingFinished.connect(self.onUpdate_model_data)
                    # 设置网格
                    setPosition(lbl, row, column, rowSpan, columnSpan, obj)

                elif widget == 'F7HeadLineEdit' and isf7:
                    lbl = Label3(label)
                    self.__lblList.append(lbl)  # 当有红字时使用，或设置样式
                    pdic = self.getF7DictByModel(self.sysAppEditModel, ixh)
                    obj = F7HeadLineEdit(pdic, self)

                    obj.setObjectName(field)

                    # 设置网格
                    setPosition(lbl, row, column, rowSpan, columnSpan, obj)

                elif widget == 'CustCheckBox':
                    lbl = None
                    obj = CustCheckBox()
                    obj.setText(label)
                    obj.setObjectName(field)
                    # 设置网格
                    setPosition(lbl, row, column, rowSpan, columnSpan, obj)


            else:
                # 将不可见的控件放入__hObj中, 仅两种，1 LineEdit，2 DateTimeEdit
                if widget == 'CustDateTimeEdit':
                    pass
                    # obj = CustDateTimeEdit()
                else:
                    obj = HeadLineEditInt()

                obj.setObjectName(field)
                obj.setEnabled(False)

            ixh += 1

            self.__hObj.append(obj)

    # mapper映射字段
    def setMapper(self, mapper):
        # mapper.clearMapping()
        x = 0
        for obj in self.__hObj:
            if obj is not None:
                if type(obj).__name__ == 'LineEditPath':
                    self.mapper.addMapping(obj.lineEdit, x)
                else:
                    self.mapper.addMapping(obj, x)
            x += 1

    def setEditPanel(self):
        """
        设置edit面板
        :return:
        """
        self.createGrid(self.gridLayout_edit)

        # 设置字段映射
        self.mapper.setModel(self.mainModel)
        self.setMapper(self.mapper)
        self.mapper.setCurrentIndex(0)
        self.setBrowsePanel(0)

    def setBrowsePanel(self, row):
        """
        设置浏览面板
        :return:
        """
        if self.mainModel.rowCount() > 0:
            firstCol = self.getFirstDisplayColumn()
            lastCol = self.getLastDisplayColumn()
            # 设置当前的索引
            index = self.mainModel.index(row, firstCol)
            self.tableView.setCurrentIndex(index)

            selection_model = self.tableView.selectionModel()
            if 0 <= row < self.mainModel.rowCount():
                index1 = self.mainModel.index(row, firstCol)
                index2 = self.mainModel.index(row, lastCol)
                # 创建选择
                selection = QItemSelection(index1, index2)
                # 设置选择
                selection_model.select(selection, QItemSelectionModel.Select)

                # 设置审核状态
                self.setAuditImage()

    #   ********************************    获取edit browse 配置数据的方法
    def getEditFieldColumn(self, field):
        """
        获取edit面板的字段的位置
        :param field:
        :return:
        """
        column = self.edit_FFieldList.index(field)
        return column

    def getBrowseColumn(self, field):
        """
        获取browse面板的字段的位置
        :param field:
        :return:
        """
        column = self.browse_FFieldList.index(field)
        return column

    def getBorwseDelegateDic(self):
        """
        获取浏览编码代理的设置5个字段的值
        :return:
        """
        pDict = {'statusFieldName': self.getA1_FStateFieldName(),
                 'enumClass': self.getA1_FEnumClass(),
                 'colorGroup': self.getA1_FColorGroup(),
                 'chioseField': self.getA1_FChoiceField(),
                 'chioseValue': self.getA1_FChoiceValue()}
        return pDict

    def onTreeItemDBClick(self, it, col):
        """
        左树双击事件
        :param it:
        :param col:
        :return:
        """
        num = it.text(0)
        iLen = len(num)

        if self.baseDbType == 'sqlite':
            condi = "substr(fnumber,1,{l})='{sfn}'".format(l=str(iLen), sfn=num)
        else:
            condi = "left(fnumber,{l}='{sf}'".format(l=str(iLen), sfn=num)

        sql = addWhereCondition_Str(self.FMainSql, condi)
        self.readData(sql)

    def getMainModel(self, sql):
        """
        根据sql, 获取表的model
        :param sql:
        :return:
        """
        pdic = {'sql': sql, 'baseDbType': self.baseDbType,
                'fieldNameList': self.browse_FFieldNameList,
                'fieldList': self.browse_FFieldList,
                'alignList': self.browse_FAlignList}

        model = TableModelMap(pdic)
        # model = TableModel(pdic)
        return model

    def getFirstDisplayColumn(self):
        """
        得到当前tableView第一个显示列的列号
        :return:
        """
        col = 0
        for visible, field in zip(self.browse_FVisibleList, self.browse_FFieldList):
            if visible:
                break
            else:
                col += 1
        return col

    def getLastDisplayColumn(self):
        """
        得到最后一个显示列的列号
        这段代码首先将列表逆序，然后使用 index() 方法找到逆序后的第一个1出现的位置，
        最后通过列表长度减去这个位置来得到原始列表中最后一个1出现的位置。
        :return:
        """
        last_index = len(self.browse_FVisibleList) - self.browse_FVisibleList[::-1].index(1) - 1
        return last_index

    def setModelFSel(self, isel):
        """
        设置model中FSel值
        :param isel:
        :return:
        """
        for row in range(0, self.mainModel.rowCount()):
            index = self.mainModel.index(row, 0)
            self.mainModel.setData(index, isel)

    def tableSave(self):
        """
        表删除记录
        :return:
        """
        fidList = list(self.mainModel.listUpdate)
        sqlList = []
        # 处理主表
        pdic = {'tableName': self.FTableName, 'model': self.mainModel, 'fidList': fidList,
                'fieldList': self.browse_FFieldList,
                'typeList': self.browse_FFieldTypeList,
                'joinList': self.browse_FJoinSqlList}
        print(self.browse_FFieldTypeList)

        # 处理新增记录
        newList = []
        if self.mainModel.dirty:
            newList = getInsertSqlList(pdic)
        upList = []
        if len(fidList) > 0:
            upList = getUpdateSqlListByModelFIdList(pdic)

        sqlList.extend(newList)
        sqlList.extend(upList)
        print(sqlList)

        ok = SqlForSave.execSqlList(sqlList, self.baseDbType)
        if ok['ret']:
            # 重读数据
            self.readData(self.FMainSql)
            self.treeWidget.clear()
            self.buildTree()
            self.mainModel.listUpdate.clear()
            self.mainModel.dirty = False

            self.setToolbarSaveButton(0)  # 设置【保存按钮】
        else:
            Infomation.info(ok['info'])

    #   ************************************ 审核/反审核相关方法  *****************************
    def setEditObjEnabled(self, iFlag):
        """
        设置编辑面板控件可用
        :return:
        """
        if iFlag:
            for obj in self.__hObj:
                obj.setEnabled(0)
        else:
            for enable, obj in zip(self.edit_FIsEditList, self.__hObj):
                if enable:
                    obj.setEnabled(enable)

    def check_toolbarFinish(self):
        """
        检查工具栏是否完成重新设置
        :return:
        """

        if self.toolbarFinish == 1:
            self.toolbarStateTimer.stop()
            self.setToolbarButtons()

    def setToolbarButtons(self):
        """
        设置【保存】【审核】【反审核】是否可用
        如何是审核状态，则【保存】【审核】不可用，【反审核】可用，如果是未审核状态，则【审核】可用，【反审核】不可用
        :return:
        """
        index = self.tableView.currentIndex()

        if not index.isValid():
            return
        iFlag = 1
        checked = self.mainModel.record(index.row()).value('FChecker')
        if checked == '' or checked == 'None':
            iFlag = 0

        if iFlag:
            # 审核状态
            auditBtn = self.getButton('审核')
            if auditBtn is not None:
                auditBtn.setEnabled(0)
            saveBtn = self.getButton('保存')
            if saveBtn is not None:
                saveBtn.setEnabled(0)
            reverseAuditBtn = self.getButton('反审核')
            if reverseAuditBtn is not None:
                reverseAuditBtn.setEnabled(1)

        else:
            reverseAuditBtn = self.getButton('反审核')
            if reverseAuditBtn is not None:
                reverseAuditBtn.setEnabled(0)
            auditBtn = self.getButton('审核')
            if auditBtn is not None:
                auditBtn.setEnabled(1)

        # 设置编辑面板控件可用
        self.setEditObjEnabled(iFlag)

    def setAuditImage(self):
        """
        设置审核图章
        :return:
        """
        index = self.tableView.currentIndex()
        if not index.isValid():
            self.lblPixmap_audit.setPixmap(QPixmap(""))
            return

        if 'FChecker'.lower() in self.browse_FFieldList:
            if self.mainModel.record(index.row()).value('FChecker') != '' and \
                    self.mainModel.record(index.row()).value('FChecker') != 'None':
                self.lblPixmap_audit.setPixmap(self.PixmapAudit)
            else:
                self.lblPixmap_audit.setPixmap(QPixmap(""))

    def onAuditAfter(self, pdict):
        """
        响应审核与反审核动作
        :param pdict:
        :return:
        """
        # 设置审核图章
        self.setAuditImage()
        self.setToolbarButtons()
